package com.cims.action.staff;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.SetUtils;

import com.cims.action.BaseAction;
import com.cims.bo.staff.StaffBO;
import com.cims.bo.staff.StaffBOImpl;
import com.cims.common.exception.BoException;
import com.cims.common.vo.Staff;
import com.cims.common.vo.Usergroup;

public class StaffAction extends BaseAction {
	
	private StaffBO staff = new StaffBOImpl();
	private List<Staff> listStaff = new ArrayList<>();
	private int staffId;
	private Staff sta = new Staff();
	
	public StaffAction() {
		
	}
	
	//list all staff
	public String list() {
		try {
			listStaff = staff.getListStaff();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return SUCCESS;
	}
	
	
	//find staff by staffid
	public String initUpdate() {
		System.out.println(staffId);
		try {
			sta = staff.findByStaffId(staffId);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
		return SUCCESS;
	}
	
	
	//update staff information
	public String update() {
		try {
			System.out.println(sta.getStaffId());
			if(staff.update(sta) == true) {
				return SUCCESS;
			}
			else {
				return ERROR;
			}
		} catch (BoException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	//create staff
	public String insert() {
		try {
			System.out.println("insert");
			staff.insert(sta);
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String delete() {
		try {
			System.out.println("delete");
			staff.delete(staffId);
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	
	public StaffBO getStaff() {
		return staff;
	}
	public void setStaff(StaffBO staff) {
		this.staff = staff;
	}
	public List<Staff> getListStaff() {
		return listStaff;
	}
	public void setListStaff(List<Staff> listStaff) {
		this.listStaff = listStaff;
	}

	public int getStaffId() {
		return staffId;
	}

	public void setStaffId(int staffId) {
		this.staffId = staffId;
	}

	public Staff getSta() {
		return sta;
	}

	public void setSta(Staff sta) {
		this.sta = sta;
	}
	
}
